﻿using AntBlazor.Extensions;

namespace AntBlazor;

/// <summary>
/// 输入组件基类。
/// </summary>
public abstract class AntInput : AntComponent
{
    /// <summary>
    /// 取得或设置是否必填。
    /// </summary>
    [Parameter] public bool Required { get; set; }

    /// <summary>
    /// 取得或设置值。
    /// </summary>
    [Parameter] public string Value { get; set; }

    /// <summary>
    /// 取得或设置占位符。
    /// </summary>
    [Parameter] public string Placeholder { get; set; }

    /// <inheritdoc />
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        Attributes.Clear();
        Attributes.AddItem("id", Id);
        Attributes.AddItem("name", Name ?? Id);
        Attributes.AddItem("value", Value);
        Attributes.AddItem("aria-required", Required);
        Attributes.AddItem("placeholder", Placeholder);
    }
}